<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>新手Go玩家导包必看 | yili的个人小站</title><meta name="keywords" content="go"><meta name="author" content="yili"><meta name="copyright" content="yili"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="已经被折磨的入土了😫">
<meta property="og:type" content="article">
<meta property="og:title" content="新手Go玩家导包必看">
<meta property="og:url" content="https://yili979.gitee.io/blog/2021/10/10/%E6%96%B0%E6%89%8BGo%E7%8E%A9%E5%AE%B6%E5%AF%BC%E5%8C%85%E5%BF%85%E7%9C%8B/index.html">
<meta property="og:site_name" content="yili的个人小站">
<meta property="og:description" content="已经被折磨的入土了😫">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/10/10/7EIQGNV4tkbO29W.jpg">
<meta property="article:published_time" content="2021-10-09T16:32:52.000Z">
<meta property="article:modified_time" content="2022-01-04T15:42:53.106Z">
<meta property="article:author" content="yili">
<meta property="article:tag" content="go">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/10/10/7EIQGNV4tkbO29W.jpg"><link rel="shortcut icon" href="/blog/img/favicon.ico"><link rel="canonical" href="https://yili979.gitee.io/blog/2021/10/10/%E6%96%B0%E6%89%8BGo%E7%8E%A9%E5%AE%B6%E5%AF%BC%E5%8C%85%E5%BF%85%E7%9C%8B/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '新手Go玩家导包必看',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-01-04 23:42:53'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/blog/css/custom.css" media="defer" onload="this.media='all'"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">28</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://i.loli.net/2021/10/10/7EIQGNV4tkbO29W.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">yili的个人小站</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">新手Go玩家导包必看</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-09T16:32:52.000Z" title="发表于 2021-10-10 00:32:52">2021-10-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-04T15:42:53.106Z" title="更新于 2022-01-04 23:42:53">2022-01-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/go/">go</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="新手Go玩家导包必看"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="新手Go玩家导包必看"><a href="#新手Go玩家导包必看" class="headerlink" title="新手Go玩家导包必看"></a>新手Go玩家导包必看</h1><p>简直了简直了，go的导包机制快要把我搞分裂了，如果你是一个go的初学者，一定也会经历下面的阶段。</p>
<p>如果你使用的编辑器是VSCode或则和Goland，则会更便于操作，如果是其他的编译器，步骤和vscode也是差不多的！</p>
<p>那么看好了我将重头开始进行教学：</p>
<p>本教程如果有错误的地方请联系文我的gmail，会进行勘误：<a href="mailto:&#x71;&#105;&#97;&#110;&#x73;&#x6f;&#110;&#x67;&#x79;&#105;&#x6e;&#x40;&#x67;&#109;&#x61;&#105;&#x6c;&#x2e;&#x63;&#111;&#109;">&#x71;&#105;&#97;&#110;&#x73;&#x6f;&#110;&#x67;&#x79;&#105;&#x6e;&#x40;&#x67;&#109;&#x61;&#105;&#x6c;&#x2e;&#x63;&#111;&#109;</a></p>
<h2 id="1-基于VScode"><a href="#1-基于VScode" class="headerlink" title="1.基于VScode"></a>1.基于VScode</h2><p>下面是我们将要执行的程序：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line"></span><br><span class="line">    sample <span class="string">&quot;github.com/elliotforbes/test-package&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    fmt.Println(<span class="string">&quot;Hello World&quot;</span>)</span><br><span class="line">    sample.MySampleFunc()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这是国外的一个课程实验包，如果你想将它通过go get 进行导入，很快你会发现</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get  github.com/elliotforbes/test-package</span><br></pre></td></tr></table></figure>

<p><img src="https://i.loli.net/2021/10/09/SvoMYXQTW1PVAj5.png" alt="image-20211009235031083"></p>
<p>这个时候你最需要做的事就是赶紧百度×</p>
<p>不对是在你的环境中添加一个代理</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go env -w GO111MODULE=on</span><br><span class="line">go env -w GOPROXY=https://goproxy.io,direct</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://goproxy.io/zh/">https://goproxy.io/zh/</a> 第三方代理</p>
<p>这是一个为全球的go语言文件提供代理的服务，你可以通过这个代理来对第三方依赖进行下载</p>
<blockquote>
<p>就好比你在maven中添加一个阿里云镜像可以更快的将依赖进行导入，当你注册镜像之后会发现下载的速度会非常之快。。</p>
</blockquote>
<p>get完之后你下载下来的源码总会存在一个地方吧，没错，代理服务为你专门提供了一个地方去保存源码，这个路径在你的{GOPATH/pkg/mod}下：</p>
<p><img src="https://i.loli.net/2021/10/09/3vlSQ5H8As4J6Kq.png" alt="image-20211009235727622"></p>
<p>如果你想在一个新建的main.go文件中使用这个包，不要急躁，还需要一步操作：</p>
<p>在你的main.go的路径下使用</p>
<p>一定要记牢这个命令！！！！，并且在新建文件之后就立马进行声明</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">go</span> mod init</span><br></pre></td></tr></table></figure>

<p><img src="https://i.loli.net/2021/10/10/bmotAp5W2CDkqzZ.png" alt="image-20211010000641223"></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> E:\go\src\main&gt; go mod init</span><br><span class="line">go: creating new go.mod: module main</span><br><span class="line">go: to add module requirements and sums:</span><br><span class="line">		go mod tidy</span><br></pre></td></tr></table></figure>

<p><img src="https://i.loli.net/2021/10/10/3eRDc6SIwOLhgEb.png" alt="image-20211010000226378"></p>
<p>然后如果你想使用这个包，就直接执行</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get +你需要的包的地址</span><br></pre></td></tr></table></figure>

<p>这里我去执行</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get  github.com/elliotforbes/test-package</span><br></pre></td></tr></table></figure>

<p>这个虽然之前是执行过的，它是已经下载到你的文件夹中了。</p>
<p>但是现在这个项目是完全访问不到你刚才下载的包的，所以这个时候你要再一次执行这个命令才可以将你这个main.go与之前下载的包相关联起来。</p>
<p>执行完毕之后你的go.mod文件会发生变化，也就是会出现一行</p>
<p><img src="https://i.loli.net/2021/10/10/T8ALeFqQE2Xym7P.png" alt="image-20211010000922797"></p>
<p>这个就代表你这个包已经对包进行引用了</p>
<p>除此之外还会出现一个go.sum文件</p>
<p><img src="https://i.loli.net/2021/10/10/m8fo6wykBlh3pxg.png" alt="image-20211010001157873"></p>
<p>这个文件表示你所以依赖的包是否引入go module，</p>
<p>如果项目打了 tag，但是没有用到 go module，为了跟用了 go module 的项目相区别，需要加个 <code>+incompatible</code> 的标志。</p>
<p>我们这次导入的包是使用了 go module 的，所以不存在这个标志</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">github.com/elliotforbes/test-package v1.0.0 h1:5YuuDaum0tX2G5EOHzsFm4ZXrsn8K341jgMFcD711WQ=</span><br><span class="line">github.com/elliotforbes/test-package v1.0.0/go.mod h1:FYNdacMBLThsqEOQ5/aiClalhO71JB7kjWdzgNhpbNE=</span><br></pre></td></tr></table></figure>

<p>如果没有使用module，则是</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">github.com/elliotforbes/test-package v1.0.0+incompatible h1:5YuuDaum0tX2G5EOHzsFm4ZXrsn8K341jgMFcD711WQ=</span><br><span class="line">github.com/elliotforbes/test-package v1.0.0/go.mod+incompatible h1:FYNdacMBLThsqEOQ5/aiClalhO71JB7kjWdzgNhpbNE=</span><br></pre></td></tr></table></figure>

<p>如果我们项目使用了module功能，在生成源文件进行运行的时候，module会根据我们所提供的信息找到对应的文件，然后将文件依赖进行导入。</p>
<p>这个时候写入我们的main.go程序，就可以愉快地使用 go run 来进行解析处理咯！！！！</p>
<p>可以看见我们导入的包被正确导入并使用</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> E:\go\src\main&gt; go run <span class="string">&quot;e:\go\src\main\main.go&quot;</span></span><br><span class="line">Hello World</span><br><span class="line">Version <span class="number">1.0</span> of this <span class="function"><span class="keyword">Function</span></span></span><br><span class="line">Hello World</span><br></pre></td></tr></table></figure>

<h2 id="2、Goland"><a href="#2、Goland" class="headerlink" title="2、Goland"></a>2、Goland</h2><p>由于goland是收费的，所以很多事情它已经帮我们做好了。</p>
<p>但是还是有一件事是我们需要做的：<strong>加代理</strong></p>
<p>下面是我们将要执行的程序：</p>
<h3 id="代理"><a href="#代理" class="headerlink" title="代理"></a>代理</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go env -w GO111MODULE=on</span><br><span class="line">go env -w GOPROXY=https://goproxy.io,direct</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://goproxy.io/zh/">https://goproxy.io/zh/</a> 第三方代理</p>
<p>这是一个为全球的go语言文件提供代理的服务，你可以通过这个代理来对第三方依赖进行下载</p>
<blockquote>
<p>就好比你在maven中添加一个阿里云镜像可以更快的将依赖进行导入，当你注册镜像之后会发现下载的速度会非常之快。。</p>
</blockquote>
<h3 id="新建文件"><a href="#新建文件" class="headerlink" title="新建文件"></a>新建文件</h3><p>在你的goland中新建一个项目</p>
<p>项目会自动生成一个go.mod</p>
<p>然后在项目中添加一个main.go程序，将下面的源码放进去：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line"></span><br><span class="line">    sample <span class="string">&quot;github.com/elliotforbes/test-package&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    fmt.Println(<span class="string">&quot;Hello World&quot;</span>)</span><br><span class="line">    sample.MySampleFunc()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后你的导入部分会爆红：</p>
<p><img src="https://i.loli.net/2021/10/10/WL1SNj2EPqbaoMs.png" alt="image-20211010002726752"></p>
<p>这个时候点击sync导入依赖，在点击后，就可以直接正常的进行使用了。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go: finding module <span class="keyword">for</span> package github.com/elliotforbes/test-package</span><br><span class="line">go: found github.com/elliotforbes/test-package <span class="keyword">in</span> github.com/elliotforbes/test-package v1.0.0</span><br></pre></td></tr></table></figure>

<p>你的项目会出现一个sum.go文件，他是链接着module的，所以可以直接导入并进行使用。</p>
<p><img src="https://i.loli.net/2021/10/10/PAvewbTgoajmqyS.png" alt="image-20211010002914758"></p>
<p>下面是执行出来的结果：</p>
<p><img src="https://i.loli.net/2021/10/10/ZDiC9TEB4UreyJa.png" alt="image-20211010003017264"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">yili</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://yili979.gitee.io/blog/2021/10/10/%E6%96%B0%E6%89%8BGo%E7%8E%A9%E5%AE%B6%E5%AF%BC%E5%8C%85%E5%BF%85%E7%9C%8B/">https://yili979.gitee.io/blog/2021/10/10/%E6%96%B0%E6%89%8BGo%E7%8E%A9%E5%AE%B6%E5%AF%BC%E5%8C%85%E5%BF%85%E7%9C%8B/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://yili979.gitee.io/blog" target="_blank">yili的个人小站</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/go/">go</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/10/10/7EIQGNV4tkbO29W.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2022/01/03/summary/2021/"><img class="prev-cover" src="https://yili979.oss-cn-beijing.aliyuncs.com/img/202201032237731.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">2021年度总结</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-6-%E6%8E%A5%E5%8F%A3/"><img class="next-cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">golang基础-6-接口</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-1-%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95/" title="golang基础-1-基础语法"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-1-基础语法</div></div></a></div><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-2-%E6%B5%81%E7%A8%8B%E8%AF%AD%E5%8F%A5/" title="golang基础-2-流程语句"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-2-流程语句</div></div></a></div><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-3-%E6%95%B0%E7%BB%84/" title="golang基础-3-数组"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-3-数组</div></div></a></div><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-4-%E5%87%BD%E6%95%B0/" title="golang基础-4-函数"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-4-函数</div></div></a></div><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-5-%E7%BB%93%E6%9E%84/" title="golang基础-5-结构"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-5-结构</div></div></a></div><div><a href="/blog/2021/10/06/golang/golang%E5%9F%BA%E7%A1%80-6-%E6%8E%A5%E5%8F%A3/" title="golang基础-6-接口"><img class="cover" src="https://i.loli.net/2021/10/06/muj2EqIY5PxMsZh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-06</div><div class="title">golang基础-6-接口</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">yili</div><div class="author-info__description">身骑白马</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">28</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/qiuyuyin"><i class="fab fa-github"></i><span>github🍟</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">啦啦啦，写的不好还请见谅😉<div class="twopeople"><div class="twopeople"><div class="container"style="height:200px;"><canvas class="illo"width="800"height="800"style="max-width: 200px; max-height: 200px; touch-action: none; width: 640px; height: 640px;"></canvas></div><script src="js/twopeople1.js"></script><script src="js/zdog.dist.js"></script><script id="rendered-js"src="js/twopeople.js"></script><style>.twopeople{margin:0;align-items:center;justify-content:center;text-align:center}canvas{display:block;margin:0 auto;cursor:move}</style></div></div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%96%B0%E6%89%8BGo%E7%8E%A9%E5%AE%B6%E5%AF%BC%E5%8C%85%E5%BF%85%E7%9C%8B"><span class="toc-text">新手Go玩家导包必看</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%9F%BA%E4%BA%8EVScode"><span class="toc-text">1.基于VScode</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81Goland"><span class="toc-text">2、Goland</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%90%86"><span class="toc-text">代理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6"><span class="toc-text">新建文件</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/something-about-crypto/" title="something about crypto"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/image-20220124000713258.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="something about crypto"/></a><div class="content"><a class="title" href="/blog/2022/03/08/something-about-crypto/" title="something about crypto">something about crypto</a><time datetime="2022-03-08T12:01:13.000Z" title="发表于 2022-03-08 20:01:13">2022-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/golang%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="golang内存管理"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/202203081958270.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="golang内存管理"/></a><div class="content"><a class="title" href="/blog/2022/03/08/golang%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="golang内存管理">golang内存管理</a><time datetime="2022-03-08T11:55:30.000Z" title="发表于 2022-03-08 19:55:30">2022-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/%E9%89%B4%E6%9D%83%E7%B3%BB%E7%BB%9F/" title="鉴权系统"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/202203081950401.jpeg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="鉴权系统"/></a><div class="content"><a class="title" href="/blog/2022/03/08/%E9%89%B4%E6%9D%83%E7%B3%BB%E7%BB%9F/" title="鉴权系统">鉴权系统</a><time datetime="2022-03-08T11:49:53.000Z" title="发表于 2022-03-08 19:49:53">2022-03-08</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By yili</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>